<?php
/**
*
* @package phpBB3
* @version $Id$
* @copyright (c) 2005 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/

/**
*/

/**
* @ignore
*/
 
define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include_once($phpbb_root_path . 'common.' . $phpEx);
include_once($phpbb_root_path . 'includes/functions_display.' . $phpEx);
include_once($phpbb_root_path . 'sv_common.' . $phpEx);
include_once($phpbb_root_path . 'prophet_common.' . $phpEx);

// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup('stockvirtual');


$corp_to_watch = get_corp_to_watch();

$mode		= request_var('mode', '');
if ($mode == 'signal_chart')
{
	$corp_id		= request_var('corp_id', '');
	$model			= request_var('model', '');

	$report_path	= request_var('report_path', '');
	
	echo " $corp_id , $model, report_path:$report_path <BR>" . PHP_EOL;
	
}


$sig_col['A'] = 19;	
$sig_col['B'] = 20;	
$sig_col['C'] = 21;	
$sig_col['D'] = 22;	
$sig_col['E'] = 23;	
$sig_col['F'] = 24;	

$predict_col['A'] = 26;	
$predict_col['B'] = 27;	
$predict_col['C'] = 28;	
$predict_col['D'] = 29;	
$predict_col['E'] = 30;	
$predict_col['F'] = 31;	

$path = $report_path . $corp_id . '.csv';

if (file_exists($path) == false)
{
	echo "$path not exist<BR>\n";
}		
	
// load csv
$raw_file 	= file_get_contents($path);
$csv 		= sv_str_getcsv ($raw_file, "\n");    
		
$i 		= 0;		
$max 	= 0;
$min 	= PHP_INT_MAX;

$closing_price = array();
$buy_sig = array();
$sell_sig = array();
$buy_predict = array();
$sell_predict = array();

// analyse classification correct rate
foreach($csv as $row)
{
	$row = sv_str_getcsv($row[0]);
	$row = $row[0];
    		
	if (is_numeric($row[6]) && $row[6] != 0)
	{
		$p = $row[6];
		$closing_price[] = $p;
		
		if ($p > $max)
			$max = $p;
		if ($p < $min)
			$min = $p;
			
		if ($row[$sig_col[$model]] == constant('PEAK'))
			$sell_sig[] = $p * 0.95;
		else
			$sell_sig[] = 0;
			
		if ($row[$sig_col[$model]] == constant('VALLEY'))
			$buy_sig[] = $p * 0.95;
		else
			$buy_sig[] = 0;
			
		if ($row[$predict_col[$model]] == constant('PEAK'))
			$sell_predict[] = $p * 0.8;
		else
			$sell_predict[] = 0;
			
		if ($row[$predict_col[$model]] == constant('VALLEY'))
			$buy_predict[] = $p * 0.8;
		else
			$buy_predict[] = 0;
	}
		
    ++$i;
}

$min = $min * 0.8;

$prices 		= implode(',', $closing_price);
$buy 			= implode(',', $buy_sig);
$sell 			= implode(',', $sell_sig);
$buy_predict 	= implode(',', $buy_predict);
$sell_predict 	= implode(',', $sell_predict);



display_forums('', $config['load_moderators']);

// include nav links.
include_nav_links();

// Assign index specific vars
$template->assign_vars(array(

	'FORUM_IMG'				=> $user->img('forum_read', 'NO_NEW_POSTS'),
	'FORUM_NEW_IMG'			=> $user->img('forum_unread', 'NEW_POSTS'),
	'FORUM_LOCKED_IMG'		=> $user->img('forum_read_locked', 'NO_NEW_POSTS_LOCKED'),
	'FORUM_NEW_LOCKED_IMG'	=> $user->img('forum_unread_locked', 'NO_NEW_POSTS_LOCKED'),

	'S_LOGIN_ACTION'			=> append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=login'),
	'S_DISPLAY_BIRTHDAY_LIST'	=> ($config['load_birthdays']) ? true : false,
	'U_MONEY'					=> number_format($money),
	
	'TAIEX_FIRST_DATE'			=> $TAIEX_first_date,
	'TAIEX_LAST_DATE'			=> $TAIEX_last_date,
	
	'LOCAL_REPORT_PATH'			=> $report_path, 	
	
	'CHART_WIDTH'				=> $i, 
	
	'CORP_ID'					=> $corp_id,
	'MODEL'						=> $model,
	'PRICES'					=> $prices,
	'BUY'						=> $buy,
	'SELL'						=> $sell,
	'BUY_PREDICT'				=> $buy_predict,
	'SELL_PREDICT'				=> $sell_predict,
	'MIN'						=> $min, 
	'MAX'						=> $max, 
		
	'U_MARK_FORUMS'		=> ($user->data['is_registered'] || $config['load_anon_lastread']) ? append_sid("{$phpbb_root_path}index.$phpEx", 'hash=' . generate_link_hash('global') . '&amp;mark=forums') : '',
	'U_MCP'				=> ($auth->acl_get('m_') || $auth->acl_getf_global('m_')) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=main&amp;mode=front', true, $user->session_id) : '')
	
	
	
);

// Output page
page_header($user->lang['SV_RULE']);

$template->set_filenames(array(
	'body' => 'prophet_chart.html')
);

page_footer();

?>